#include <stdio.h>

#define MAX_CITED 1001

int hIndex(int* citations, int citationsSize) {
    int s[ MAX_CITED ]= { [0 ... 1000] =0};
    for( int i=0; i<citationsSize; i++ )
        s[ citations[i] ] ++;
    int ad=0;
    for( int i=1000; i>=0; i-- ){
        s[i]+=ad;
        ad=s[i];
        if( s[i] >= i )
            return i;
    }
}

int main(){
    //int c[]={1,3,1};
    int c[]={3,0,6,1,5};
    printf("%d\n",hIndex(c,sizeof(c)/sizeof(int)));
    return 0;
}
